#include "histogram.h"
#include "distances.h"
#include "abscissasemivariogram.h"
#include <QDebug>


Histogram::Histogram()
{


}

void Histogram::setNBins(int nBins){

    this->nbins = nBins;
}

int Histogram::getNBins(){
    return this->nbins;
}

double Histogram::getMaxDistance(){
    return this->maxDistance;
}

double Histogram::getMinDistance(){
    return 0;
   // return this->minDistance;
}

void Histogram::setMinDistance(double minDistance){
    this->minDistance = minDistance;
}




void Histogram::setMaxDistance(double maxDistance){

    this->maxDistance = (maxDistance * 3)/10;


}

void Histogram::setAbscissas(QVector< QVector<double> > mappedDistances){

    qDebug()<< "VALORES DE X";
    //qDebug()<< "VERIFICANDO ABSCISSAS";
    double step = this->getStep();

    //qDebug() << "Step: " << step;

    //int count = 0;

    double lowerLimit = 0;
    double upperLimit = step;

    for(int i = 0; i< this->nbins; i++){

       // qDebug()<< "Barra " << i;

        AbscissaSemivariogram* abscissa = new AbscissaSemivariogram();

        abscissa->setValue(lowerLimit);
        qDebug()<< abscissa->getValue();

       // qDebug()<< "Entre " << lowerLimit << "e " << upperLimit ;
        QList<int> indexOfOperators = Distances::getIndexOfOperators(mappedDistances,lowerLimit,upperLimit);
        abscissa->setIndexesOfThePoints(indexOfOperators);

       // qDebug()<< "Quantidade de distancias nessa barra " << (indexOfOperators.size()/2);
        //count = count + indexOfOperators.size()/2;
        this->abscissas.append(abscissa);

        lowerLimit = upperLimit;
        upperLimit = upperLimit + step;
    }

   // qDebug()<<" Total de distancias" << count;

    this->setUpperLimit(lowerLimit);

    //qDebug()<< "Upper " << this->getUpperLimit();





}




double Histogram::getStep(){

    double step = 0;

    step = this->maxDistance / this->nbins;

    //step = 56.8661;
    return step;

}

QList<AbscissaSemivariogram*> Histogram::getAbscissas(){
    return this->abscissas;
}


void Histogram::setLowerLimit(double lowerLimit){
    this->lowerLimit = lowerLimit;
}

void Histogram::setUpperLimit(double upperLimit){
    this->upperLimit = upperLimit;
}

double Histogram::getLowerLimit(){
    return this->lowerLimit;
}

double Histogram::getUpperLimit(){
    return this->upperLimit;
}


QList<double> Histogram::getValueOfAbscissas(){

    QList<double> values;

    for (int i = 0; i< this->abscissas.size(); i++){
        values.append(this->abscissas.at(i)->getValue());
    }


    return values;
}



